﻿#region License
// Copyright (c) 2009 Shun Chi Guo
// E-Mail:shuncy@gmail.com
// Blog:http://shuncy.cnblogs.com
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace shun.PAPLib
{
    public static class ErrorCode
    {
        static Dictionary<string, string> lsError = new Dictionary<string, string>();
        static ErrorCode()
        {
            lsError.Add("1000", "请求成功");
            lsError.Add("1001", "请求接受");
            lsError.Add("2000", "错误的请求,语法错误");
            lsError.Add("2001", "禁止,请求拒绝");
            lsError.Add("2002", "错误地址,找不到要求客户端");
            lsError.Add("2003", "指定的地址未找到");
            lsError.Add("2004", "找不到Push-ID");
            lsError.Add("2005", "能力不匹配,PI假定能力与客户端不符");
            lsError.Add("2006", "不支持要求的功能,客户端不支持输入的格式");
            lsError.Add("2007", "复本PushID,PPG内的PushID不唯一");
            lsError.Add("2008", "取消失败");
            lsError.Add("3000", "内部服务器错误");
            lsError.Add("3001", "未实现");
            lsError.Add("3002", "版本不支持");
            lsError.Add("3003", "不可能,消息不可用导致不能执行");
            lsError.Add("3004", "不支持能力匹配，PPG不支持push消息提供的客户端能力");
            lsError.Add("3005", "不支持多地址，PPG不支持指名多个接受者的操作");
            lsError.Add("3006", "转换失败，PPG不能执行信息的转换");
            lsError.Add("3007", "不能使用要求的传输方法，PPG不能执行指明的确认或非确认传送");
            lsError.Add("3008", "能力不可用，特定客户端的能力不可用");
            lsError.Add("3009", "不能用要求网络，请求的网络不可用");
            lsError.Add("3010", "不能用要求承载，请求的承载不可用");
            lsError.Add("3011", "不支持替换，PPG不支持替换操作");
            lsError.Add("4000", "服务失败，客户端可以重试操作");
            lsError.Add("4001", "服务不可用，服务器忙");

            lsError.Add("-1000", "执行调用失败");
        }

        /// <summary>
        /// 根据错误代码取得错误的信息
        /// </summary>
        /// <param name="code">要取得的错误代码</param>
        /// <returns></returns>
        public static string GetErrorInfo(string code)
        {
            code = code.Trim();
            if (lsError.ContainsKey(code))
            {
                return lsError[code];
            }

            if (code.StartsWith("5"))
            {
                return "移动客户终止操作";
            }
            return "未知的错误代码["+code+"]";
        }
    }
}
